﻿<ResourceDictionary
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:Controls="clr-namespace:System.Windows.Controls">

    <Style TargetType="{x:Type Controls:TreeViewExItem}" x:Key="TreeViewExBaseStyle">
        <Style.Triggers>
            <DataTrigger
                    Binding="{Binding (VirtualizingStackPanel.IsVirtualizing), RelativeSource={RelativeSource AncestorType={x:Type Controls:TreeViewEx}}, FallbackValue=True}"
                    Value="True">
                <Setter Property="ItemsControl.ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel IsItemsHost="True" />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </DataTrigger>
        </Style.Triggers>
        <Style.Resources>
            <ResourceDictionary />
        </Style.Resources>
        <Setter Property="KeyboardNavigation.IsTabStop" Value="False" />
        <Setter Property="VirtualizingStackPanel.VirtualizationMode"
                Value="{Binding (VirtualizingStackPanel.VirtualizationMode), RelativeSource={RelativeSource AncestorType={x:Type Controls:TreeViewEx}}, FallbackValue=Standard}" />
        <Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="False" />
        <Setter Property="Panel.Background" Value="#00FFFFFF" />
        <Setter Property="Control.HorizontalContentAlignment"
                Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}, FallbackValue=Left}" />
        <Setter Property="Control.VerticalContentAlignment"
                Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}, FallbackValue=Center}" />
        <Setter Property="Control.Padding" Value="1" />
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Margin" Value="0" />
        <Setter Property="FrameworkElement.FocusVisualStyle">
            <Setter.Value>
                <Style TargetType="{x:Type IFrameworkInputElement}">
                    <Style.Resources>
                        <ResourceDictionary />
                    </Style.Resources>
                    <Setter Property="Control.Template">
                        <Setter.Value>
                            <ControlTemplate>
                                <Rectangle />
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Setter.Value>
        </Setter>
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:TreeViewExItem}">
                    <StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <ToggleButton
                                    IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:TreeViewExItem}},Path=IsExpanded,FallbackValue=False}"
                                    ClickMode="Press" Name="Expander" DockPanel.Dock="Top">
                                <ToggleButton.Style>
                                    <Style TargetType="{x:Type ToggleButton}">
                                        <Style.Resources>
                                            <ResourceDictionary />
                                        </Style.Resources>
                                        <Setter Property="UIElement.Focusable" Value="False" />
                                        <Setter Property="FrameworkElement.Width" Value="16" />
                                        <Setter Property="FrameworkElement.Height" Value="16" />
                                        <Setter Property="Control.Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="{x:Type ToggleButton}">
                                                    <Border Padding="5" Background="#00FFFFFF" Width="16" Height="16">
                                                        <Path Fill="#00FFFFFF" Stroke="#FF989898" Name="ExpandPath">
                                                            <Path.Data>
                                                                <PathGeometry Figures="M0,0L0,6L6,0z" />
                                                            </Path.Data>
                                                            <Path.RenderTransform>
                                                                <RotateTransform Angle="135" CenterX="3" CenterY="3" />
                                                            </Path.RenderTransform>
                                                        </Path>
                                                    </Border>
                                                    <ControlTemplate.Triggers>
                                                        <Trigger Property="UIElement.IsMouseOver" Value="True">
                                                            <Setter Property="Shape.Stroke" TargetName="ExpandPath">
                                                                <Setter.Value>
                                                                    <SolidColorBrush>
                                                                        #FF1BBBFA</SolidColorBrush>
                                                                </Setter.Value>
                                                            </Setter>
                                                            <Setter Property="Shape.Fill" TargetName="ExpandPath">
                                                                <Setter.Value>
                                                                    <SolidColorBrush>#00FFFFFF</SolidColorBrush>
                                                                </Setter.Value>
                                                            </Setter>
                                                        </Trigger>
                                                        <Trigger Property="ToggleButton.IsChecked" Value="True">
                                                            <Setter Property="UIElement.RenderTransform"
                                                                    TargetName="ExpandPath">
                                                                <Setter.Value>
                                                                    <RotateTransform Angle="180" CenterX="3" CenterY="3" />
                                                                </Setter.Value>
                                                            </Setter>
                                                            <Setter Property="Shape.Fill" TargetName="ExpandPath">
                                                                <Setter.Value>
                                                                    <SolidColorBrush>#FF595959</SolidColorBrush>
                                                                </Setter.Value>
                                                            </Setter>
                                                            <Setter Property="Shape.Stroke" TargetName="ExpandPath">
                                                                <Setter.Value>
                                                                    <SolidColorBrush>#FF262626</SolidColorBrush>
                                                                </Setter.Value>
                                                            </Setter>
                                                        </Trigger>
                                                    </ControlTemplate.Triggers>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </ToggleButton.Style>
                            </ToggleButton>
                            <Border BorderThickness="{TemplateBinding Border.BorderThickness}"
                                    Padding="{TemplateBinding Control.Padding}" x:Name="headerBorder"
                                    BorderBrush="{Binding BorderBrush, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"
                                    Background="{TemplateBinding Panel.Background}" SnapsToDevicePixels="True"
                                    Grid.Column="1" CornerRadius="2" VerticalAlignment="Center" DockPanel.Dock="Left">
                                <ContentPresenter FocusManager.IsFocusScope="True"
                                        Content="{TemplateBinding HeaderedContentControl.Header}"
                                        ContentTemplate="{TemplateBinding HeaderedContentControl.HeaderTemplate}"
                                        ContentStringFormat="{TemplateBinding HeaderedItemsControl.HeaderStringFormat}"
                                        ContentSource="Header" Name="PART_Header"
                                        HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                                        VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
                                        SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
                            </Border>
                        </StackPanel>
                        <ItemsPresenter Name="ItemsHost" Grid.ColumnSpan="2">
                            <ItemsPresenter.Margin>
                                <Thickness Left="{x:Static Controls:Constants.ItemIndent}" />
                            </ItemsPresenter.Margin>
                        </ItemsPresenter>
                    </StackPanel>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsVisible" Value="False">
                            <Setter Property="FrameworkElement.Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="Controls:TreeViewExItem.IsMouseOver" Value="True" SourceName="PART_Header">
                            <Setter Property="Control.Background"
                                    Value="{Binding BackgroundHovered, RelativeSource={RelativeSource Self}}" />
                            <Setter Property="Border.BorderBrush"
                                    Value="{Binding BorderBrushHovered, RelativeSource={RelativeSource Self}}" />
                        </Trigger>
                        <Trigger Property="Controls:TreeViewExItem.IsSelected" Value="True">
                            <Setter Property="Control.Background"
                                    Value="{Binding BackgroundSelected, RelativeSource={RelativeSource Self}}" />
                            <Setter Property="Border.BorderBrush"
                                    Value="{Binding BorderBrushSelected, RelativeSource={RelativeSource Self}}" />
                        </Trigger>
                        <Trigger Property="Controls:TreeViewExItem.IsFocused" Value="True">
                            <Setter Property="Border.BorderBrush"
                                    Value="{Binding BorderBrushFocused, RelativeSource={RelativeSource Self}}" />
                            <Setter Property="Control.Background"
                                    Value="{Binding BackgroundFocused, RelativeSource={RelativeSource Self}}" />
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="Controls:TreeViewExItem.IsMouseOver" Value="True" />
                                <Condition Property="Controls:TreeViewExItem.IsSelected" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Border.BorderBrush"
                                    Value="{Binding BorderBrushSelectedHovered, RelativeSource={RelativeSource Self}}" />
                            <Setter Property="Control.Background"
                                    Value="{Binding BackgroundSelectedHovered, RelativeSource={RelativeSource Self}}" />
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="Controls:TreeViewExItem.IsFocused" Value="True" />
                                <Condition Property="Controls:TreeViewExItem.IsSelected" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter Property="Border.BorderBrush"
                                    Value="{Binding BorderBrushFocusedSelected, RelativeSource={RelativeSource Self}}" />
                            <Setter Property="Control.Background"
                                    Value="{Binding BackgroundFocusedSelected, RelativeSource={RelativeSource Self}}" />
                        </MultiTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition
                                        Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=IsActive, FallbackValue=False}"
                                        Value="False" />
                                <Condition
                                        Binding="{Binding RelativeSource={RelativeSource Mode=Self}, Path=IsSelected}"
                                        Value="True" />
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Border.BorderBrush"
                                    Value="{Binding BorderBrushInactive, RelativeSource={RelativeSource Self}}" />
                            <Setter Property="Control.Background"
                                    Value="{Binding BackgroundInactive, RelativeSource={RelativeSource Self}}" />
                        </MultiDataTrigger>
                        <Trigger Property="Controls:TreeViewExItem.IsExpanded" Value="False">
                            <Setter Property="UIElement.Visibility" TargetName="ItemsHost" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="ItemsControl.HasItems" Value="False">
                            <Setter Property="UIElement.Visibility" TargetName="Expander" Value="Hidden" />
                        </Trigger>
                        <Trigger Property="UIElement.IsEnabled" Value="False">
                            <Setter Property="TextElement.Foreground">
                                <Setter.Value>
                                    <DynamicResource ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
                                </Setter.Value>
                            </Setter>
                        </Trigger>
                        <!--<Trigger Property="IsEditable" Value="False">
                            <Setter Property="TextElement.Foreground" TargetName="PART_Header">
                                <Setter.Value>
                                    <DynamicResource ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
                                </Setter.Value>
                            </Setter>
                        </Trigger>-->
                        <Trigger Property="Controls:TreeViewExItem.IsEditing" Value="True">
                            <Setter Property="HeaderTemplate"
                                    Value="{Binding ContentTemplateEdit, RelativeSource={RelativeSource Self}}" />
                            <Setter Property="Padding" Value="0" />
                            <Setter Property="Control.Background"
                                    Value="{Binding BackgroundSelected, RelativeSource={RelativeSource Self}}" />
                            <Setter Property="Border.BorderBrush"
                                    Value="{Binding BorderBrushSelected, RelativeSource={RelativeSource Self}}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>